package com.flyee.viewer
{
	import com.flyee.utils.CamberGraph;
	
	import flash.display.BlendMode;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.geom.Matrix;
	/**
	 * 主UI上显示主角的血量和魔法值的图形，图形角度的设置反映玩家当前血量和魔法的
	 * 增减情况。 
	 * @author work131
	 * 
	 */	
	public class HMPViewer extends Sprite implements Destroy
	{
		/**
		 * 表示血量的图形 
		 */		
		private var hpShape:Shape = null;
		/**
		 * 表示魔法的图形 
		 */		
		private var mpShape:Shape = null;
		/**
		 * 内圆半径 
		 */		
		private const radiusIn:int = 55;
		/**
		 * 外圆半径 
		 */		
		private const radiusOut:int = 80;
		/**
		 * 血量的环行图形生成类
		 */		
		private var hpCamber:CamberGraph = null;
		/**
		 * 魔法的环行图形生成类 
		 */		
		private var mpCamber:CamberGraph = null;
		/**
		 * 遮照图形 
		 */		
		private var maskShape:Shape = null;
		/**
		 * 血量和魔法量的最大角度，用于计算当前血量和魔法值反映的图形角度 
		 */		
		private const showAngle:int = 138;
		/**
		 * 构造方法 
		 * 
		 */		
		public function HMPViewer()
		{
			init();
		}
		/**
		 * 初始化方法 
		 * 
		 */		
		private function init():void{
			HPArc();
			MPArc();
			filter();
			setMask();
			this.addChild(maskShape);
			this.addChild(hpShape);
			this.addChild(mpShape);
		}
		/**
		 * 显示血量的图形 
		 * 
		 */		
		private function HPArc():void{
			var hpColors:Array = [0xFF0000,0XFF0000];
			hpCamber = new CamberGraph(radiusOut,radiusOut,radiusIn,radiusOut,hpColors,90);
			hpShape = new Shape();
			hpCamber.drawCirque(hpShape.graphics,180);
		}
		/**
		 * 显示魔法的图形 
		 * 
		 */		
		private function MPArc():void{
			var mpColors:Array = [0x0066CC,0x0066CC];
			mpCamber =  new CamberGraph(radiusOut,radiusOut,radiusIn,radiusOut,mpColors,90);
			mpShape = new Shape();
			mpCamber.drawCirque(mpShape.graphics,180);
		}
		/**
		 * 根据血量计算图形的角度 
		 * @param rest 当前数量值
		 * @param max 最大数量值
		 * @return 计算后的角度
		 * 
		 */		
		private function calculateAngle(rest:int,max:int):int{
			return Math.floor((rest * this.showAngle)/max)+42;
		}
		/**
		 * 设置遮照 
		 * 
		 */		
		private function setMask():void{
			maskShape = new Shape();
			maskShape.graphics.beginFill(0xFF0000,0.5);
			maskShape.graphics.drawRect(0,0,radiusOut + radiusOut,122);
			maskShape.graphics.endFill();
			this.mask = maskShape;
		}
		/**
		 * 加过滤器，内侧发光
		 * 
		 */		
		private function filter():void{
			var filter:GlowFilter = new GlowFilter();
			var filters:Array = new Array();
			
			filter.blurX = 8;
			filter.blurY = 8;
			filter.alpha = 0.65;
			filter.quality = BitmapFilterQuality.HIGH;
			filter.strength = 3;
			filter.knockout = false;
			filter.inner = true;
			filter.color = 0X000000;
			filters.push(filter);
			
			mpShape.filters = filters;
			mpShape.transform.matrix = new Matrix(-1,0,0,1,mpShape.width,0);
			mpShape.x = radiusOut + radiusOut;
			mpShape.blendMode = BlendMode.ADD; 
			
			hpShape.filters = filters;
			hpShape.blendMode = BlendMode.ADD;
		}
		/**
		 * 重绘血量的图形
		 * @param rest 当前血量
		 * 
		 */		
		public function setHP(rest:int,max:int = 500):void{
			var maxHP:int = max;
			var hp:int = rest;
			var degree:int = calculateAngle(hp,maxHP);;
			hpCamber.drawCirque(hpShape.graphics,degree);
		}
		/**
		 * 重绘魔法图形
		 * @param rest 当前魔法
		 * 
		 */		
		public function setMP(rest:int,max:int = 500):void{
			var maxMP:int = max;
			var mp:int = rest;
			var degree:int = calculateAngle(mp,maxMP);
			mpCamber.drawCirque(mpShape.graphics,degree);
		}
		
		public function dispose():void{
			
		}
	}
}